from ckeditor_uploader.fields import RichTextUploadingField
from django.contrib import auth
from django.db import models

# Create your models here.
from mlh.utils.models import BaseModel
from users.models import User


class Activities(BaseModel):
    """活动模型类"""
    STATE_CHOICES = (
        (0, '报名即将开始'),
        (1, '立即报名'),
        (2, '活动进行中'),
        (3, '活动结束'),
    )
    title = models.CharField(max_length=32,  verbose_name='活动标题')
    image = models.ImageField(upload_to="activities/", verbose_name='封面')
    start_time = models.DateTimeField( verbose_name="开始时间")
    end_time = models.DateTimeField( verbose_name="结束时间")
    city = models.CharField(max_length=16,  verbose_name='城市')
    intro = RichTextUploadingField(default='', verbose_name='活动介绍')
    desc = RichTextUploadingField(default='', verbose_name='活动详情')
    sponsor = models.CharField(max_length=32,  verbose_name='举办方')
    address = models.CharField(max_length=64,  verbose_name='举办地点')
    related_links = models.CharField(max_length=64,  verbose_name='相关链接')
    apply_state = models.SmallIntegerField(choices=STATE_CHOICES, default=0, verbose_name='活动状态')
    apply_deadline = models.DateTimeField(auto_now=True, verbose_name="结束时间")
    is_delete = models.BooleanField(default=False, verbose_name='是否删除')
    create_user = models.ForeignKey(User, verbose_name='创建用户')


    class Meta:
        db_table = 'tb_activities'
        verbose_name = '活动'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.title


class activities_apply(BaseModel):
    """活动报名表"""

    activities_id = models.ForeignKey(Activities, verbose_name='活动')
    user_id = models.ForeignKey(User, verbose_name='报名用户')
    is_delete = models.BooleanField(default=False, verbose_name='逻辑删除')

    class Meta:
        db_table = 'tb_activities_apply'
        verbose_name = '活动报名'
        verbose_name_plural = verbose_name
